package com.shrct.businessprocess.customerservice.impl;

import com.shrct.businessprocess.customerservice.RCRoutineService;
import com.shrct.businessprocess.customerservice.RCRoutineServiceItem;
import com.shrct.businessprocess.customerservice.RCRoutineServiceItemStatus;
import com.shrct.businessprocess.customerservice.impl.RCRoutineServiceImpl;
import com.shrct.businessprocess.customerservice.proxy.RCRoutineServiceItemProxy;
import edu.fudan.mylang.pf.BaseModelObject;
import edu.fudan.mylang.pf.IObjectFactory;
import java.util.Date;
import javax.persistence.CascadeType;
import javax.persistence.DiscriminatorColumn;
import javax.persistence.DiscriminatorValue;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;
import org.eclipse.xtext.xbase.lib.Procedures.Procedure1;
import org.hibernate.annotations.DiscriminatorOptions;

@Entity
@DiscriminatorValue("RCROUTINESERVICEITEM_TYPE")
@DiscriminatorOptions(force = true)
@DiscriminatorColumn(length = 64)
@Table(name = "rcroutineserviceitem")
public class RCRoutineServiceItemImpl extends BaseModelObject implements RCRoutineServiceItem {
  public RCRoutineServiceItemImpl() {
    super();
  }
  
  public RCRoutineServiceItemImpl(final RCRoutineService rountineService) {
    super();
    this.rountineService = rountineService;
  }
  
  @JoinColumn(name = "rountineService_id")
  @ManyToOne(targetEntity = RCRoutineServiceImpl.class, cascade = { CascadeType.MERGE, CascadeType.PERSIST })
  private RCRoutineService rountineService;
  
  public RCRoutineService getRountineService() {
    return this.rountineService;
  }
  
  public RCRoutineServiceItem setRountineService(final RCRoutineService rountineService) {
    this.rountineService = rountineService;
    return this;			
    
  }
  
  private Date planDate;
  
  public Date getPlanDate() {
    return this.planDate;
  }
  
  public RCRoutineServiceItem setPlanDate(final Date planDate) {
    this.planDate = planDate;
    return this;			
    
  }
  
  private RCRoutineServiceItemStatus status = RCRoutineServiceItemStatus.unscheduled;
  
  public RCRoutineServiceItemStatus getStatus() {
    return this.status;
  }
  
  public RCRoutineServiceItem setStatus(final RCRoutineServiceItemStatus status) {
    this.status = status;
    return this;			
    
  }
  
  public void scheduled() {
    this.status = RCRoutineServiceItemStatus.scheduled;
  }
  
  public void assigned() {
    this.status = RCRoutineServiceItemStatus.assigned;
  }
  
  public void finished() {
    this.status = RCRoutineServiceItemStatus.finished;
    this.rountineService.finishedOnce();
  }
  
  public static RCRoutineServiceItem create(final RCRoutineService rountineService, final IObjectFactory objectFactory) {
    com.shrct.businessprocess.customerservice.RCRoutineServiceItem rCRoutineServiceItem = new com.shrct.businessprocess.customerservice.impl.RCRoutineServiceItemImpl(
    	rountineService
    );
    objectFactory.create(rCRoutineServiceItem);
    return rCRoutineServiceItem;			
    
  }
  
  public static RCRoutineServiceItem createRCRoutineServiceItemImpl(final RCRoutineService rountineService, final IObjectFactory objectFactory, final Procedure1<RCRoutineServiceItem> init) {
    com.shrct.businessprocess.customerservice.RCRoutineServiceItem rCRoutineServiceItem = new com.shrct.businessprocess.customerservice.impl.RCRoutineServiceItemImpl(
    	rountineService
    );
    objectFactory.create(rCRoutineServiceItem);
    init.apply(rCRoutineServiceItem);
    
    return rCRoutineServiceItem;			
    
  }
  
  public RCRoutineServiceItemProxy toProxy() {
    com.shrct.businessprocess.customerservice.proxy.RCRoutineServiceItemProxy proxy = new com.shrct.businessprocess.customerservice.proxy.RCRoutineServiceItemProxy();
    proxy.setId(this.getId());
    if(this instanceof edu.fudan.mylang.pf.INamedModelObject){
    	proxy.setName(((edu.fudan.mylang.pf.INamedModelObject)this).getEntityName());
    }
    return proxy;
    
  }
}
